home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 127_01.zip / RAP.H < prev    next >
Text File  |  1993-06-17  |  15KB  |  520 lines

  1. /*********************************************************************\
  2. ** .---------------------------------------------------------------. **
  3. ** |                                                               | **
  4. ** |                                                               | **
  5. ** |         Copyright (c) 1981, 1982, 1983 by Eric Martz.         | **
  6. ** |                                                               | **
  7. ** |                                                               | **
  8. ** |       Permission is hereby granted to use this source         | **
  9. ** |       code only for non-profit purposes. Publication of       | **
  10. ** |       all or any part of this source code, as well as         | **
  11. ** |       use for business purposes is forbidden without          | **
  12. ** |       written permission of the author and copyright          | **
  13. ** |       holder:                                                 | **
  14. ** |                                                               | **
  15. ** |                          Eric Martz                           | **
  16. ** |                         POWER  TOOLS                          | **
  17. ** |                    48 Hunter's Hill Circle                    | **
  18. ** |                      Amherst MA 01002 USA                     | **
  19. ** |                                                               | **
  20. ** |                                                               | **
  21. ** `---------------------------------------------------------------' **
  22. \*********************************************************************/
  23.  
  24. /*--------------------------------------------------------------------------
  25.  
  26. HEADER FILE FOR "ROFF AND PRINT" = RAP by Eric Martz.
  27. The RAP program is built on ROFF.C by Kathy Bacon, which was obtained
  28. from the BDSC Users Group. ROFF.C, in turn, is an adaptation of
  29. Kernighan and Plauger's ROFF in RATFOR in their book Software Tools.
  30.  
  31. The first functional RAP was created in August-October 1981.
  32. Debugging, additions and augmentations have continued through the
  33. present (August, 1983).
  34.  
  35. --------------------------------------------------------------------------
  36. KNOWN BUGS:
  37.  
  38.     1. Tabs not working if line has substitutions.
  39.     
  40.     2. Justification (spread()) doesnt work.
  41.  
  42. --------------------------------------------------------------------------
  43. Obsolete Bug (autospacing code has been defeated)
  44.  
  45.          No double space after period ending sentence when sentence
  46.         ends at end of input line. Difficult to correct since getspaces()
  47.         cant look ahead to see if next word is capitalized. Left as is
  48.         in accord with preference to fail to double space rather than
  49.         put in inappropriate double spaces, e.g. a line ending in Dr.
  50.         Somebody as does the previous line.
  51.  
  52. --------------------------------------------------------------------------
  53.  
  54. FILE LOCATIONS OF RAP FUNCTIONS:
  55.  
  56. P=RAP.C
  57. 1=RAP1.C etc.
  58. R=RAPREAD.C
  59.  
  60. FUNCTION    FILE    CALLS
  61. -----------------------------------------------------------
  62. main            P    dioinit, init_defaults, anotherline,
  63.                 command, text, dioflush
  64.  
  65. anotherline    3    saveextra, rapgets, ss, expand_controls
  66.  
  67. baud            R    rapgets, de-comment
  68.  
  69. biggets        4
  70.  
  71. brk            3
  72.  
  73. center        1
  74.  
  75. checkbig        4
  76.  
  77. command        1    comtyp, get_val, brk, set, checkbig, gettl, read_command
  78.                 find_portion, getpairs, restore_mode, space
  79.  
  80. comtyp        1
  81.  
  82. de_comment    4
  83.  
  84. expand_controls3
  85.  
  86. expantab        4
  87.  
  88. fillbuf        3
  89.  
  90. fillulbuf        3    getspaces, fillbuf
  91.  
  92. find_portion    R    rapgets
  93.  
  94. getpairs        4    ssgets, de_comment, ioport, baud
  95.  
  96. getspaces        3
  97.  
  98. gettl        2    skip_blanks, substitute
  99.  
  100. getval        1
  101.  
  102. getwrd        3    
  103.  
  104. indent        2
  105.  
  106. init_defaults    P
  107.  
  108. init_ss        4    rapgets, de_comment, checkbig, command, getpairs
  109.  
  110. init_text        2
  111.  
  112. ioport        R    rapgets, de_comment
  113.  
  114. leadbl        2
  115.  
  116. open_read        R
  117.  
  118. phead        2    skip, puttl
  119.  
  120. pfoot        2    skip, puttl
  121.  
  122. put            2    phead, indent, putline, skip, pfoot
  123.  
  124. putline        3    ss, indent
  125.  
  126. puttl        2    ss, restore_mode
  127.  
  128. putwrd        3    brk, fillbuf
  129.  
  130. rapgets        4    biggets
  131.  
  132. read_command    R    open_read
  133.  
  134. restore_mode    2
  135.  
  136. saveextra        3
  137.  
  138. screen_status    R
  139.  
  140. set            1
  141.  
  142. skip            2
  143.  
  144. skip_blanks    1
  145.  
  146. space        2    brk, skip, pfoot
  147.  
  148. spread        1    trunc_bl
  149.  
  150. ss            4    delchars, substitute, checkbig
  151.  
  152. ssgets        4    rapgets
  153.  
  154. text            2    init_text, space, leadbl, expantab, fillulbuf,
  155.                 put, restore_mode, center, getwrd, getspaces,
  156.                 putwrd, checkbig
  157.  
  158. trunc_bl        1
  159.  
  160. --------------------------------------------------------------------------*/
  161.  
  162. #include <bdscio.h>
  163. #include "bdscio+.h"
  164.  
  165. /*--------------------------------------------------------------------------
  166. Version history:
  167.  
  168. 1.0->1.1:
  169.  
  170. Change of input file does not automatically begin a new page.
  171. Initialization string comes from {init{ in SS#.
  172. Bug in }RF} fixed.
  173. \\ // -> {{ }}
  174.  
  175. 1.1->1.2:
  176.  
  177. Don't double space after a period unless preceding word length > 3.
  178. Replace {#{ with auto-incrementing arabic number.
  179. Direct "no ss0 file" error message to STDERR.
  180.  
  181. 1.2->2.0:
  182. Implemented ".re filename portion" command.
  183. Implemented {ux{/{dx{ macro expansion for super/sub-scripts.
  184. Implemented .ss 1/0 command.
  185. Made PORT_OUT the dioinit() default.
  186.  
  187. 2.0->2.0a:
  188. Implemented built-in substitutions.
  189. Changed SS0-9 to SSx...
  190. Added .d1, .d2, .ou.
  191. Implemented commands in SS capability, i/o port, baud in SS.
  192.  
  193. 2.0a->2.0b = 2.00
  194. Rearranged argument parsing so '>/...' overrides .ou in SS.
  195. Added '>' to zero _Outflag.
  196. Fixed head/foot flushing and centering for proportional fonts.
  197. Implemented '.bo' command.
  198. Implemented VIEW capability.
  199.  
  200. 2.00 -> 2.10
  201. Changed SSFILE to FILE.SS to work with Microshell. (DEFAULT.SS)
  202. Used #ifdef DEBUG to remove all debugging code to reduce size.
  203. Linked with L2 to reduce size. Externals 8c00.
  204. #defined FILENAME as 16 to accept drive specification.
  205. Fixed badname() to accept drive specification.
  206. Implemented Deinit, Interrupted (with ^C dioflush()).
  207. Added backspace to cancel space from console in view mode.
  208.  
  209. 2.10 -> 2.11
  210. Changed NAKED_NEWLINE from ^N to ^] ("group separator", ASCII 1Dh, 29d)
  211. Redirection mark '/' changed to ')'
  212.  
  213. 2.11 -> 2.12
  214. {#{ is incremented only when {#+{; only one per input line.
  215. A repeated original ss string causes the new replacement to replace the
  216.     former replacement.
  217.  
  218. 2.12 -> 2.13
  219.     .br now starts a ".pi" paragraph (Tival = Pival).
  220.  
  221. 2.13 -> 2.14
  222.     .fn range 0-5 expanded to 0-16
  223.  
  224. 2.14 -> 2.15
  225. added }"console prompt} feature
  226. added }wait} function
  227. added .cf continuous forms
  228. added .bl blanking character
  229. arranged to have lines beginning with an invalid command passed into text()
  230.  
  231. 2.15 -> 2.16
  232. deleted NAKED_NEWLINE feature
  233. added "compress control" feature with exception for ^J (->naked)
  234.     to allow ^Z
  235.  
  236. 2.16 -> 2.17
  237. made non-continuous forms not wait at page bottoms with -p# flag
  238.  
  239. 2.17 -> 2.18
  240. fixed underlining when }u+} not defined and filling in putwrd()
  241.     to account for post-substitutions and backspaces
  242.  
  243. 2.18 -> 2.19
  244. Added .lf command for printers which generate auto-lf on cr; also, when
  245.     .lf 1, a literal cr (as in a segmented header) generates a Rev_lf.
  246.  
  247. 2.19 -> 2.20
  248. Removed coded licensee ident; commented out portion code with .re.
  249. Made getspaces() use same spacing as input text.
  250. Added {_...{, {!...{.
  251. Rebuilt underlining and boldfacing code, all processing at output.
  252.     Added shift and restore for each.
  253. Bug which failed to break at blank line containing spaces fixed.
  254. Added 10 new dot commands: .ar, .bd, .ed, .i@, .ig, .ix, .ne,
  255.     .p#, .pd, .tc.
  256.  
  257. 2.20 -> 2.21
  258. Defeated blank-squeezing in ss()
  259. Fixed centering to ignore leading/trailing white
  260.  
  261. --------------------------------------------------------------------------*/
  262. /*--------------------------------------------------------------------------
  263.  
  264. GENERAL PURPOSE CONSTANTS
  265.  
  266. --------------------------------------------------------------------------*/
  267.  
  268. #define    STDERR        4
  269. /* send error messages to console while in DIO */
  270.  
  271. #define    CTRL_C        '\3'
  272. #define    BIGBUF        512
  273. #define    HUGE            135    /* generally large number */
  274. #define    FILENAME        16    /* big enough for cp/m name A:12345678.123 */
  275. #define    COMMAND        '.'    /* all commands starts with this */
  276.  
  277. #define    LIST_OUT    2
  278. #define    UNKNOWN        -1    /* returned if doesn't recg. command */
  279. #define    NO_VAL        -32760    /* returned when no argument w/commad */
  280.  
  281. #define    CR            0x0D
  282. #define    FORMFEED        '\12'
  283. #define    FORCEPRINT    0
  284. #define    SPACE        ' '
  285. #define    BACKSPACE        '\b'
  286. #define    TAB            '\t'
  287. #define    BLANK        ' '
  288. #define    DASH            '-'
  289.  
  290. #define    WAIT            "\227"    /* meta control W */
  291. #define    PROMPT        "\220" /* meta control P */
  292.  
  293. /* BDOS CALLS ETC */
  294. #define    CONIN        1
  295. #define    CON_STATUS    11
  296. #define    CONOUT        2
  297.  
  298. /*--------------------------------------------------------------------------
  299.  
  300. FORMATTING COMMANDS TO BE IMBEDDED IN INPUT TEXT
  301.  
  302. --------------------------------------------------------------------------*/
  303.  
  304. #define    AR    1    /* arabic for {#{ */
  305. #define    BD    2    /* begin draft */
  306. #define    BL    3    /* blank out character */
  307. #define    BO    4    /* bold */
  308. #define    BP    5    /* begin page  */
  309. #define    BR    6    /* causes break */
  310. #define    CC    7    /* compress controls */
  311. #define    CE    8    /* center line(s) */
  312. #define    CF    9    /* continuous forms */
  313. #define    D1    10   /* pre ss delim */
  314. #define    D2    11    /* post ss delim */
  315. /*
  316. #define    DEBUG    12    /* turn on Debug */
  317. */
  318. #define    EC    13    /* expand control characters */
  319. #define    ED    14    /* end draft */
  320. #define    FI    15    /* fill lines */
  321. #define    FN    16    /* select primary font */
  322. #define    FO    17    /* footer title */
  323. #define    HE    18    /* header title */
  324. #define    IAT    19    /* ignore leading @ */
  325. #define    IC    20    /* ignore subsequent commands */
  326. #define    IG    21    /* ignore */
  327. #define    IN    22    /* left indent */
  328. #define    IX    23    /* index */
  329. #define    JU    24    /* justify */
  330. #define    LF    25    /* on: expand LF to CR+LF; off: issue CR only */
  331. #define    LS    26    /* line spacing */
  332. #define    M1    27    /* top margin */
  333. #define    M2    28    /* second top margin */
  334. #define    M3    29    /* first bottom margin */
  335. #define    M4    30    /* bottom-most margin       */
  336. #define    MO    31    /* restore mode on Sanders */
  337. #define    NEED    32    /* lines needed else new page; NE conflicts with != */
  338. #define    NF    33    /* no fill */
  339. #define    NJ    34    /* no justify */
  340. #define    NX    35    /* next input file name */
  341. #define    OU    36    /* _Outflag */
  342. #define    PI    37    /* paragraph indent */
  343. #define    PD    38    /* print draft */
  344. #define    PL    39    /* set page length */
  345. #define    PNO    40    /* set page # */
  346. #define    POST_SS    41    /* }} replacement off/on */
  347. #define    RE    42    /* read sub input file/portion */
  348. #define    PRE_SS    43    /* {{ replacement off/on */
  349. #define    RF    44    /* restore font to primary/default */
  350. #define    RM    45    /* set right margin */
  351. #define    SA    46    /* select/deselect Sanders printer */
  352. #define    SP    47    /* add blank line(s) */
  353. #define    SS    48    /* input additional ss pairs */
  354. #define    TA    49    /* set tab modulus */
  355. #define    TC    50    /* table of contents */
  356. #define    TI    51    /* temporary indent */
  357. #define    TP    52    /* read in file at next top of page */
  358. #define    UL    53    /* underline line(s) */
  359.  
  360. /*--------------------------------------------------------------------------
  361.  
  362. CONSTANTS FOR STRING SUBSTITUTION (SS) UTILITY
  363.  
  364. --------------------------------------------------------------------------*/
  365.  
  366. #define    MAXPACK 2048 /* dimension of Oldnewbuf */
  367. #define    MAXPAIRS 100
  368.  
  369. /*--------------------------------------------------------------------------
  370.  
  371. FILE I/O
  372.  
  373. --------------------------------------------------------------------------*/
  374.  
  375. #define NIOBUFS 2 /* 2 needed only for subread capability */
  376. #include <fio1.h>
  377.  
  378. /*--------------------------------------------------------------------------
  379.  
  380. EXTERNALS BEGIN HERE
  381.  
  382. --------------------------------------------------------------------------*/
  383. #ifdef DEBUG
  384. int Debug;
  385. #endif
  386.  
  387. int
  388.     Arabic,        /* autoincrementing number replaces {#{ */
  389.     Bottom,        /* last live line */
  390.     Bo_input,
  391.     Bo_plus,
  392.     Carat,
  393.     Ce_input,        /* set equal to number of lines to be Centered */
  394.     Comp_carat,
  395.     Con_forms,    /* continuous forms */
  396.     Curpag,        /* current output page number, init = 0 */
  397.     Dir,            /* for "spreading" of lines    */
  398.     End_wait,        /* if set, wait at bottom of current page */
  399.     Exp_ctrl_chars,/* expand control characters, e.g. '\0' to ^@ */
  400.     Extrafull,
  401.     Fill,        /* set to YES or NO, default YES */
  402.     First_text,    /* Yes until first text line encountered */
  403.     Font,        /* Current primary Sanders font */
  404.     Ignore_at,    /* on for ingnore leading @ */
  405.     In_linecnt,    /* line count in input file */
  406.     In_main,        /* line count in main while reading sub file */
  407.     Index,        /* on for index */
  408.     Indraft,        /* input text between .bd and .ed */
  409.     Interrupted,    /* flag used in putchar to deal with multiple ^C's */
  410.     Inval,        /* left indent -> default  0 */
  411.     Justify,        /* YES or NO, default NO */
  412.     Lineno,        /* next line to be printed, init = 0 */
  413.     Lines_out,
  414.     Lsval,        /* line spacing value -> default will be 1 */
  415.     M1val,        /* margin before and including header */
  416.     M2val,        /* margin after header */
  417.     M3val,        /* margin after last text line */
  418.     M4val,        /* bottom margin, including footer */
  419.     Newpag,        /* next output page number, init = 1 */
  420.     Oldnewtot,
  421.     Outlen,
  422.     Outwrds,        /* no. words in outbuf, init = 0 */
  423.     Pagestop,
  424.     Pdata,
  425.     Pimask,
  426.     Pival,        /* paragraph indent, default Inval+5 */
  427.     Plval,        /* page length in lines, init=66 */
  428.     Pomask,
  429.     Post_ss,        /* // delimited ss off/on */
  430.     Pre_ss,        /* \\ delimited ss off/on */
  431.     Pready,
  432.     Preset,
  433.     Presetval,
  434.     Press_all,    /* Set if SSn contains non-delimited original strings */
  435.     Press_flg,    /* Line contains pre format substitution delimiters */
  436.     Print_at,        /* on suppresses printing until page # = Print_at */
  437.     Printdraft,    /* on for print draft */
  438.     Prompt,
  439.     Pstatus,
  440.     Rmval,        /* right margin */
  441.     Sanders,        /* set to YES or NO for Sanders Printer */
  442.     Screen_size,
  443.     Skip_cnt,
  444.     Spacecnt,
  445.     Spval,        /* blank lines to be spaced down */
  446.     Ss_pair_cnt,
  447.     Suppress_lf,    /* on for printers which auto lf on cr */
  448.     Tabcont,        /* on for table of contents */
  449.     Tabval,        /* tabulation modulus, default 5 */
  450.     Tival,        /* temporary indent -> default  0 */
  451.     Ul_input,        /* set equal to number of lines to be underlined */
  452.     Ul_plus,
  453.     Wordlen;
  454.  
  455. char
  456.     *Bar,
  457.     *Bo_off,
  458.     *Bo_on,
  459.     *Bo_restore,
  460.     *Bo_shift,
  461.     *Center_mode,
  462.     *Deinit,
  463.     *Flush_left,
  464.     *Flush_right,
  465.     *Font_c,
  466.     *Font_o,
  467.     *Forceprint,
  468.     *Init,
  469.     *Just_one,
  470.     *Just_two,
  471.     *Newstring[MAXPAIRS],
  472.     *Nextin,
  473.     *Nextout,
  474.     *Oldstring[MAXPAIRS],
  475.     *Pp[16],
  476.     *Rev_lf,
  477.     *Ul_off,
  478.     *Ul_on,
  479.     *Ul_restore,
  480.     *Ul_shift,
  481.     *Wordbegin,
  482.     *Wordend;
  483.  
  484. char    
  485.     Blank_c,    /* Character to blank out */
  486.     Extralines[BIGBUF],
  487.     Footer[ MAXLINE ],    /* footer title */
  488.     Header[ MAXLINE ],    /*  header title */
  489.     Inbuf[BIGBUF],
  490.     Nxname[FILENAME],
  491.     Oldnewbuf[MAXPACK],
  492.     Outbuf[BIGBUF],
  493.     Post_ss_delim,
  494.     Pre_ss_delim,
  495.     Ss_name[FILENAME],
  496.     Ulbuf[BIGBUF];
  497.  
  498. /*
  499. /* FOR SUB-READ WITH PORTIONS */
  500.  
  501. #define PORTIT_O "[[" /* PORTION TITLE OPENING DELIMITER */
  502. #define PORTIT_C "]]" /* PORTION TITLE CLOSING DELIMITER */
  503. int Old_portion, New_portion;
  504. */
  505. char Fn_main[FILENAME], Fn_read[FILENAME];
  506. FILE *Fpin, *Fp_main, *Fp_read;
  507.  
  508. /* NEEDED BY RAPIO.C */
  509.  
  510. int _Outflag;
  511. char Out_file[FILENAME];
  512. char _Dobuf[BUFSIZ];    /* I/O buffers used for direction  */
  513. int Xflag;
  514.  
  515. #define SCREEN_SIZE 20
  516.  
  517. /*--------------------------------------------------------------------------
  518.         END OF RAP.H
  519. --------------------------------------------------------------------------*/
  520.